package cn.ctodb.openapi.idcard.web.rest;

import cn.ctodb.openapi.idcard.service.IdcardService;
import cn.ctodb.openapi.idcard.service.dto.IdcardDTO;
import com.codahale.metrics.annotation.Timed;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by cc on 2017/3/31.
 */
@Api(value = "API:信息核验服务")
@RestController
@RequestMapping("/api")
public class IdcardResource {

    @Resource
    private IdcardService idcardService;

    @Timed
    @PostMapping("/idcard")
    @ApiOperation(value = "公安身份验证接口")
    public ResponseEntity<IdcardDTO> idcheck(@RequestHeader("apikey") String apikey, @RequestParam(value = "name") String name, @RequestParam(value = "cardno") String cardno) {
//        User user = userService.getByApikey(apikey);
//        if (user == null) { return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); }
        IdcardDTO dto = idcardService.idc(name, cardno);
        return new ResponseEntity<>(dto, HttpStatus.OK);
    }
}
